package com.itheima.goods.controller.admin;


import com.itheima.goods.dto.SetmealDTO;
import com.itheima.goods.dto.SetmealPageQueryDTO;
import com.itheima.goods.service.SetmealService;
import com.itheima.goods.vo.SetmealVO;
import com.itheima.result.PageBean;
import com.itheima.result.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐相关接口")
@Slf4j
public class SetmealController {


    @Autowired
    private SetmealService setmealService;

    /**
     * 分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result page(SetmealPageQueryDTO setmealPageQueryDTO){
        PageBean pageBean= setmealService.pageSelect(setmealPageQueryDTO);
        return Result.success(pageBean);

    }

    /**
     * 套餐起售、停售
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status, Long id){
        setmealService.update(status,id);
        return Result.success();

    }

    /**
     * 批量删除套餐
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result delete(Long[] ids){
        setmealService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 新增套餐
     * @param setmealDTO
     * @return
     */
    @PostMapping
    public Result add(@RequestBody SetmealDTO setmealDTO){
        System.out.println(setmealDTO+"==========================");
        setmealService.addSetneal(setmealDTO);
        return Result.success();
    }

    /**
     * 根据套餐id查询套餐以及其下菜品
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<SetmealDTO> find(@PathVariable Long id){
        System.out.println(id+"================");
        SetmealDTO setmealDTO=setmealService.findById(id);
        return Result.success(setmealDTO);
    }

    /**
     * 修改套餐
     * @param setmealVO
     * @return
     */

    @PutMapping
    public Result update(@RequestBody SetmealVO setmealVO){
        setmealService.updateSetmeal(setmealVO);
        return Result.success();

    }

}